var activity = require('../models/activity'),
    apiHandler = require('../services/api-handler'),
    mailer = require('../mailer/mailer'),
    timeAgo = require('node-time-ago');

exports.getAllActivities = function (req, res) {
    var data;
    activity.getAllActivities(req.body.userId, req.body, apiHandler.handler.check(res, 'NO_ACTIVITY', function (activityList) {
        if (!activityList || activityList.length == 0) {
            data = {
                activityList: [],
                activityCount: 0
            };
            apiHandler.setSuccessResponse(data, res);
        } else {
            activityList.forEach(function (activityData) {
                activityData.timeAgo = timeAgo(activityData.createdAt);
            });
            data = {
                activityList: activityList,
                activityCount: activity.length
            };
            apiHandler.setSuccessResponse(data, res);
        }
    }));
};

exports.getAllActivitiesByDate = function (req, res) {
    activity.getAllActivitiesByDate(req.body, apiHandler.handler.check(res, 'NO_ACTIVITY', function (activityList) {
        activity.getAllActivitiesByDateCount(req.body, apiHandler.handler.check(res, 'NO_ACTIVITY', function (activityCount) {
            var data = {
                activityCount: activityCount.length,
                activityList: activityList
            };
            apiHandler.setSuccessResponse(data, res);
        }));
    }));
};